package com.welink.cmp.convertor;

import com.welink.cmp.dao.metadata.dataobject.RouterDO;
import com.welink.cmp.domain.metadata.Router;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 路由器转换器
 */
public class RouterConvertor {

    /**
     * 将 Domain 对象转换为 DataObject 对象
     *
     * @param router 路由器领域对象
     * @return 路由器数据对象
     */
    public static RouterDO toDataObject(Router router) {
        if (router == null) {
            return null;
        }
        RouterDO routerDO = new RouterDO();
        routerDO.setId(router.getId());
        routerDO.setAssetsId(router.getAssetsId());
        routerDO.setSn(router.getSn());
        routerDO.setName(router.getName());
        routerDO.setVendor(router.getVendor());
        routerDO.setBrand(router.getBrand());
        routerDO.setModel(router.getModel());
        routerDO.setUnitSize(router.getUnitSize());
        routerDO.setRackNo(router.getRackNo());
        routerDO.setRackUnitPosition(router.getRackUnitPosition());
        routerDO.setDataCenterCode(router.getDataCenterCode());
        routerDO.setExpirationTime(router.getExpirationTime());
        routerDO.setLaunchedTime(router.getLaunchedTime());
        routerDO.setOs(router.getOs());
        routerDO.setMajorVersion(router.getMajorVersion());
        routerDO.setPatchVersion(router.getPatchVersion());
        routerDO.setBmcIp(router.getBmcIp());
        routerDO.setIps(router.getIps());
        routerDO.setSnatIps(router.getSnatIps());
        routerDO.setDnatIps(router.getDnatIps());
        routerDO.setBandwidth(router.getBandwidth());
        routerDO.setOpsBandwidth(router.getOpsBandwidth());
        routerDO.setStatus(router.getStatus());
        routerDO.setCreateTime(router.getCreateTime());
        routerDO.setUpdateTime(router.getUpdateTime());
        routerDO.setCreateBy(router.getCreateBy());
        routerDO.setUpdateBy(router.getUpdateBy());
        return routerDO;
    }

    /**
     * 将 DataObject 对象转换为 Domain 对象
     *
     * @param routerDO 路由器数据对象
     * @return 路由器领域对象
     */
    public static Router toDomainObject(RouterDO routerDO) {
        if (routerDO == null) {
            return null;
        }
        Router router = new Router();
        router.setId(routerDO.getId());
        router.setAssetsId(routerDO.getAssetsId());
        router.setSn(routerDO.getSn());
        router.setName(routerDO.getName());
        router.setVendor(routerDO.getVendor());
        router.setBrand(routerDO.getBrand());
        router.setModel(routerDO.getModel());
        router.setUnitSize(routerDO.getUnitSize());
        router.setRackNo(routerDO.getRackNo());
        router.setRackUnitPosition(routerDO.getRackUnitPosition());
        router.setDataCenterCode(routerDO.getDataCenterCode());
        router.setExpirationTime(routerDO.getExpirationTime());
        router.setLaunchedTime(routerDO.getLaunchedTime());
        router.setOs(routerDO.getOs());
        router.setMajorVersion(routerDO.getMajorVersion());
        router.setPatchVersion(routerDO.getPatchVersion());
        router.setBmcIp(routerDO.getBmcIp());
        router.setIps(routerDO.getIps());
        router.setSnatIps(routerDO.getSnatIps());
        router.setDnatIps(routerDO.getDnatIps());
        router.setBandwidth(routerDO.getBandwidth());
        router.setOpsBandwidth(routerDO.getOpsBandwidth());
        router.setStatus(routerDO.getStatus());
        router.setCreateTime(routerDO.getCreateTime());
        router.setUpdateTime(routerDO.getUpdateTime());
        router.setCreateBy(routerDO.getCreateBy());
        router.setUpdateBy(routerDO.getUpdateBy());
        return router;
    }

    /**
     * 将 Domain 对象列表转换为 DataObject 对象列表
     *
     * @param routers 路由器领域对象列表
     * @return 路由器数据对象列表
     */
    public static List<RouterDO> toDataObjectList(List<Router> routers) {
        return routers.stream()
                .map(RouterConvertor::toDataObject)
                .collect(Collectors.toList());
    }

    /**
     * 将 DataObject 对象列表转换为 Domain 对象列表
     *
     * @param routerDOs 路由器数据对象列表
     * @return 路由器领域对象列表
     */
    public static List<Router> toDomainObjectList(List<RouterDO> routerDOs) {
        return routerDOs.stream()
                .map(RouterConvertor::toDomainObject)
                .collect(Collectors.toList());
    }
}
